<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="renderer" content="webkit">
    <link rel="stylesheet" href="/mdui/css/mdui.min.css">
    <script defer src="/mdui/js/mdui.min.js"></script>
    <script src="/js/axios.min.js"></script>
    <script src="/js/qs.min.js"></script>
    <script src="/js/common.js"></script>
    <script src="/js/vue.js"></script>
</head>
<body class="mdui-theme-primary-indigo mdui-theme-accent-pink">


<div class="mdui-container-fluid" id="app">

    <h1 class="mdui-text-color-theme">发起审批</h1>
    <!-- 固定标签 -->
    <div class="mdui-textfield">
        <i class="mdui-icon material-icons">account_circle</i>
        <label class="mdui-textfield-label">主题</label>
        <input class=" mdui-textfield-input" type="text" v-model="meeting.title"/>
    </div>

    <!-- 固定标签 -->
    <div class="mdui-textfield">
        <i class="mdui-icon material-icons">account_circle</i>
        <label class="mdui-textfield-label">会议内容</label>
        <textarea class="mdui-textfield-input" placeholder="请输入内容" v-model="meeting.content"></textarea>
    </div>
    <!-- 固定标签 -->
    <div class="mdui-textfield">
        <i class="mdui-icon material-icons">account_circle</i>
        <label class="mdui-textfield-label">会议日期</label>
        <input class=" mdui-textfield-input" type="date" v-model="meeting.meetingDate"/>
    </div>
    <!-- 固定标签 -->
    <div class="mdui-textfield">
        <i class="mdui-icon material-icons">account_circle</i>
        <label class="mdui-textfield-label">开始时间</label>
        <input class=" mdui-textfield-input" type="time" v-model="meeting.startTime"/>
    </div>
    <!-- 固定标签 -->
    <div class="mdui-textfield">
        <i class="mdui-icon material-icons">account_circle</i>
        <label class="mdui-textfield-label">结束时间</label>
        <input class="mdui-textfield-input" type="time" v-model="meeting.endTime"/>
    </div>
    <!-- 固定标签 -->
    <div class="mdui-textfield">
        <i class="mdui-icon material-icons">account_circle</i>
        <label class="mdui-textfield-label">会议室</label>
        <input class="mdui-textfield-input" type="text" v-model="meeting.meetingRoom.roomName"/>
    </div>

    <div class="mdui-textfield">
        <i class="mdui-icon material-icons">account_circle</i>
        <label class="mdui-textfield-label">参会人员</label>
        <textarea rows="4" cols="40" readonly v-model="username"></textarea>
        <div>
            <button mdui-dialog="{target: '#dialog'}"
                    class="mdui-btn mdui-btn-raised mdui-ripple mdui-color-green-800">选择人员
            </button>

        </div>
    </div>

    <div style="text-align: center">
        <button @click="addMeeting" class="mdui-btn mdui-btn-raised mdui-ripple mdui-color-green-800">新增</button>
        <a href="javascript:history.go(-1)" class="mdui-btn mdui-btn-raised mdui-ripple mdui-color-green-800">返回</a>
    </div>
    <!--  选人的对话框-->
    <div class="mdui-dialog" id="dialog">
        <div class="mdui-dialog-title">请选择人员</div>
        <div class="mdui-dialog-content">
            <div class="mdui-row-md-4">
                <div class="mdui-col" v-for="u in users">
                    <label class="mdui-checkbox">
                        <input type="checkbox" :value="u.id"/>
                        <i class="mdui-checkbox-icon"></i>
                        {{u.name}})
                    </label>
                </div>

            </div>
        </div>
        <div class="mdui-dialog-actions">
            <button class="mdui-btn mdui-ripple" mdui-dialog-close>取消</button>
            <button class="mdui-btn mdui-ripple" mdui-dialog-confirm>确定</button>
        </div>
    </div>

</div>

<script>
    let params = new URLSearchParams(location.search)
    let meetingId = params.get("id");

    let vm = new Vue({
        el: '#app',
        data: {
            username: '',//已选人员的姓名
            rooms: [],
            users: [],
            meeting: {
                title: "",
                content: "",
                meetingDate: '',
                startTime: '',
                endTime: '',
                rooId: 0,
                userId: "",
                meetingUsers: [],
            },

        },

        created() {
            let _this = this;
            axios.get("/meeting/find?id=" + meetingId)
                .then(function (res) {
                    _this.meeting = res.data;
                    let arr = []
                    for (let u of _this.meeting.meetingUsers) {
                        arr.push(u.name)
                    }
                    _this.username = arr.toString()
                })
            this.getMeetingRoom();
            this.findUsers()

        },
        methods: {
            findUsers() {
                let _this = this
                axios.get("/user/list")
                    .then(function (res) {
                        _this.users = res.data
                    })
            },
            addMeeting() {
                if (this.meeting == "") {
                    mdui.alert("请输入主题")
                    return
                }
                if (this.content == "") {
                    mdui.alert("请输入内容")
                    return;
                }
                if (this.meetingDate == "") {
                    mdui.alert("请输入会议日期")
                    return;
                }
                if (this.startTime == "" || this.endTime == "") {
                    mdui.alert("请输入会起始时间")
                    return;
                }
                if (this.meeting.rooId == 0) {
                    mdui.alert("请选择会议室")
                    return;
                }
                this.meeting.userId = sessionStorage.getItem("userId");//获取用户id
                let _this = this;
                axios.post("/meeting/add", this.meeting)
                    .then(function (res) {
                        if (res.data.success) {
                            mdui.alert("操作成功")
                            _this.meeting = {
                                title: "",
                                content: "",
                                meetingDate: '',
                                startTime: '',
                                endTime: '',
                                userId: 0,
                                rooId: 0,
                                meetingUsers: [],
                            }
                        } else {
                            mdui.alert(res.data.msg)
                        }
                    })
            },
            getMeetingRoom() {
                let _this = this;
                axios.get("/meetingroom/list")
                    .then(function (res) {
                        _this.rooms = res.data;
                    })
            }
        },
    })

    //监听对画框的确定按钮事件
    document.getElementById("dialog").addEventListener("confirm.mdui.dialog", function () {
        let checkedusers = document.querySelectorAll("input[type='checkbox']:checked")//选中的元素数组
        let arr = []
        vm.meeting.meetingUsers = []
        for (let el of checkedusers) {
            console.log(el.parentElement.innerText)
            arr.push(el.parentElement.innerText);
            vm.meeting.meetingUsers.push({id: el.value});

        }
        vm.username = arr.toString();


    })

</script>

</body>
</html>